package com.suncm3kw.chatgpt.entity;

import lombok.Getter;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import com.suncm3kw.chatgpt.StaticValue;
import java.nio.charset.StandardCharsets;

public class SseEmitterUTF8 extends SseEmitter {

    private boolean isDone=false;

    @Getter
    private String sseId;

    public SseEmitterUTF8(String sseId) {
        super(StaticValue.SSE_TIMEOUT);
        this.sseId=sseId;
    }
    
    @Override
    protected void extendResponse(ServerHttpResponse outputMessage) {
        super.extendResponse(outputMessage);

        HttpHeaders headers = outputMessage.getHeaders();
        headers.setContentType( new MediaType("text", "event-stream", StandardCharsets.UTF_8));
    }

    public boolean isDone() {
        return !isDone;
    }

    public void setDone(boolean done) {
        isDone = done;
    }

}
